import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
import render from './helpers/render';
import './global/style/reset.css';
import '@nutui/nutui-react/dist/style.css'
import magicStore from '@/store/magic';
import get from 'lodash/get';
import 'whatwg-fetch'

render(<App />);

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();

console.log('development===>', process.env.NODE_ENV);
if (process.env.NODE_ENV === 'development') {
    // magicStore.triggerUserId('112')
    // fetch('http://itom.sxqc.com:18080/docp/gateway/api/v1/auth?module=builddaping', {
    //     method: 'GET',
    // }).then(result => result.json()).then(data => {
    //     console.log(data.authResults, 'data')
    //     let arr = data.authResults || [];
    //     if (arr.length > 0) {
    //         magicStore.triggerUserId(get(data, 'iuser.id', '123'))
    //         return
    //     } else {
    //         window.location.assign('http://124.115.230.43:18080/douc/api/v1/sso/source/index.html?restapi=http%3A%2F%2F124.115.230.43%3A18080%2Fgateway%2FcheckLogin&service=http%3A%2F%2F124.115.230.43%3A18080%2Fbuild%2Findex.html%23%2Fhome')
    //     }

    // }).catch(error => {
    //     window.location.assign('http://124.115.230.43:18080/douc/api/v1/sso/source/index.html?restapi=http%3A%2F%2F124.115.230.43%3A18080%2Fgateway%2FcheckLogin&service=http%3A%2F%2F124.115.230.43%3A18080%2Fbuild%2Findex.html%23%2Fhome')
    //     });
} else {
    fetch('http://124.115.230.43:18080/docp/gateway/api/v1/auth?module=builddaping', {
        method: 'GET',
    }).then(result => result.json()).then(data => {
        // console.log(data.authResults, 'data')
        let arr = data.authResults || [];
        if (arr.length > 0) {
            magicStore.triggerUserId(get(data, 'iuser.id', ''))
            return
        } else {
            window.location.assign('http://124.115.230.43:18080/douc/api/v1/sso/source/index.html?restapi=http%3A%2F%2F124.115.230.43%3A18080%2Fgateway%2FcheckLogin&service=http%3A%2F%2F124.115.230.43%3A18080%2Fbuild%2Findex.html%23%2Fhome')
        }
    })
        .catch(error => {
            window.location.assign('http://124.115.230.43:18080/douc/api/v1/sso/source/index.html?restapi=http%3A%2F%2F124.115.230.43%3A18080%2Fgateway%2FcheckLogin&service=http%3A%2F%2F124.115.230.43%3A18080%2Fbuild%2Findex.html%23%2Fhome')
        });
}




